/*************************************************************************
    > File Name: client.cpp
    > Author: Lancer
    > Mail: 18826075768@163.com
************************************************************************/

#include <iostream>
#include <pthread.h>
#include <string>
using namespace std;

struct arg{
    int a;
    string s;
};

void* say_hello(void* args){
    arg  i = *(arg*)args;
    cout << "hello from thread!" << endl;
    cout << "i = " << i.a <<endl;
    cout << "string is " << i.s << endl;
    pthread_exit((void*)1);
}

int main(){
    pthread_t tid;
    arg para;
    para.a = 5;
    para.s = "hello world!";
    int ret = pthread_create(&tid, nullptr, say_hello, &para);

    if(ret){
        cout << "pthread_create error: ret = " << ret <<"!" <<endl;
        return ret;
    }

    void* retval;
    ret = pthread_join(tid, &retval);

    if(ret){
        cout << "pthread_join error : ret = " << ret << "!" <<endl;
        return ret;
    }

    cout << "retval = " << long(retval) << endl;
    return 0;
}